﻿using AlibabaCloud.OpenApiClient.Models;
using AlibabaCloud.SDK.Dysmsapi20170525;
using AlibabaCloud.SDK.Dysmsapi20170525.Models;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;

namespace JSLCloud.Framework.Sms
{
    /// <summary>
    /// 阿里云短信发送工具
    /// </summary>
    public static class AliyunSmsHelper
    {
        private static Client CreateClient()
        {
            var config = new Config
            {
                AccessKeyId = "LTAI5t8gaK5Efv4jo1Hu912o",
                AccessKeySecret = "x53k9ZyulY6bHmk8w9B3mWbnca8kxM"
            };
            return new Client(config);
        }

        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="list"></param>
        public static void SendSms(List<MessageEntity> list)
        {
            var client = CreateClient();
            var sendRequest = new SendSmsRequest
            {
                PhoneNumbers = string.Join(",", list.Select(p => p.Tel).ToArray()),
                SignName = "见实力工业服务云平台",
                TemplateCode = "SMS_227258455",
                TemplateParam = JsonConvert.SerializeObject((new { xmzh = list[0].xmzh }))
            };
          var res = client.SendSms(sendRequest);         

        }

    }

    /// <summary>
    /// 需要发送的消息
    /// </summary>
    public class MessageEntity
    {
        /// <summary>
        /// 项目制号
        /// </summary>
        public string xmzh { get; set; }
        /// <summary>
        /// 电话号码
        /// </summary>
        public string Tel { get; set; }
    }
}
